<style type="text/css">
#ajaxAddTaskOperateForm .form-body .form-group{
    width:33%;
    float:left;
}
#ajaxAddTaskOperateForm .form-body .form-group .col-xs-3{
    width:45%;
}
#ajaxAddTaskOperateForm .form-body .form-group .col-xs-4{
    width:45%;
}
.ECalendarBox{
    z-index:100;
}
.ECalendarBox .currentdate h2{
    margin-top:0px;
}
.modal-dialog{
    width:1180px;
}
</style>
<link href="<?=image_url('/static/assets/global/css/ecalendar-style.css')?>" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="<?=image_url('/static/js/Ecalendar.jquery.min.js')?>"></script>
<?=form_open('', Array('class'=>'form-horizontal', 'role'=>'form', 'id'=>'ajaxAddTaskOperateForm', 'data-category-id'=>$task->id, 'name' => 'ajaxAddTaskOperateForm', 'onsubmit' => 'return submitForm()'))?>
	<div class="portlet-body form">
		<input type="hidden" id="update_time" name="update_time" value="<?=set_value('update_time', $obj->update_time)?>" />
		<div class="form-body">
			<?=edit_form_input('task_id', set_value('task_id', $task->id), '任务ID','readonly="readonly"')?>
			<?=edit_form_input('', set_value('', $obj->operator_id?$allReviewAdmins[$obj->operator_id]:$currentAdminName), '接单者','readonly="readonly"')?>
			<?=edit_form_input('product_amount', set_value('product_amount', $obj->product_amount), '商品金额','id="product_amount"')?>
			<?=edit_form_input('yunfei', set_value('yunfei', $obj->yunfei), '运费','id="yunfei"')?>
			<hr style="clear:both;"></hr>
			<?=edit_form_input('contact', set_value('contact', $obj->contact), '联系方式')?>
			<?=edit_form_input('order_no', set_value('order_no', $obj->order_no), '下单号')?>
			<?=edit_form_input('comment_link', set_value('comment_link', $obj->comment_link), '评论链接')?>
			<?=edit_form_input('order_time', set_value('order_time', $obj->order_time>0?date('Y/m/d',$obj->order_time):''), '下单时间','id="order_time" autoComplete="off"')?>
			<?=edit_form_input('pay_time', set_value('pay_time', $obj->pay_time>0?date('Y/m/d',$obj->pay_time):''), '付款时间','id="pay_time" autoComplete="off"')?>
			
			<hr style="clear:both;"></hr>
			<?=edit_form_dropdown('pay_method',IOSS_StaticConfig::getPayMethod(), set_value('pay_method', $obj->pay_method), '为客户付款的方式')?>
			<?=edit_form_dropdown('coin_type',IOSS_StaticConfig::getcoinTypeInfo(), set_value('coin_type', $obj->coin_type), '为客户付款币种','id="coin_type"')?>
			<?=edit_form_input('pay_account', set_value('pay_account', $obj->pay_account), '客户收款账号','id="pay_account"')?>
			<?=edit_form_input('commission', set_value('commission', $obj->commission), '客户要求佣金','id="commission"')?>
			<?=edit_form_input('fees', set_value('fees', $obj->fees), '为客户付款手续费','id="fees"')?>
			<hr style="clear:both;"></hr>
			<?=edit_form_dropdown('intror_pay_method',IOSS_StaticConfig::getPayMethod(), set_value('intror_pay_method', $obj->intror_pay_method), '为中介付款的方式')?>
			<?=edit_form_dropdown('intror_coin_type',IOSS_StaticConfig::getcoinTypeInfo(), set_value('intror_coin_type', $obj->intror_coin_type), '为中介付款币种','id="intror_coin_type"')?>
			<?=edit_form_input('intror_pay_account', set_value('intror_pay_account', $obj->intror_pay_account), '中介收款账号','id="intror_pay_account"')?>
			<?=edit_form_input('intror_commission', set_value('intror_commission', $obj->intror_commission), '中介要求费用','id="intror_commission"')?>
			<?=edit_form_input('intror_fees', set_value('intror_fees', $obj->intror_fees), '为中介付款手续费','id="intror_fees"')?>
			<a id="culculate" class="btn green right">计算页面中手续费</a>
			<hr style="clear:both;"></hr>
			<?=edit_form_input('pay_total', set_value('pay_total', $obj->pay_total), '实际支付金额','id="pay_total"')?>
			<span id="summry" style="color:#00aa00;line-hight:38px;font-size:15px;"></span>
			<hr style="clear:both;"></hr>
			<?=edit_form_uploader('pay_image',set_uploader('pay_image', $obj->pay_image), '付款截图')?>
			<?=edit_form_uploader('pay_image_1',set_uploader('pay_image_1', $obj->pay_image_1), '附加截图1')?>
			<?=edit_form_uploader('pay_image_2',set_uploader('pay_image_2', $obj->pay_image_2), '附加截图2')?>
			<?=edit_form_uploader('pay_image_3',set_uploader('pay_image_3', $obj->pay_image_3), '附加截图3')?>
			<?=edit_form_uploader('pay_image_4',set_uploader('pay_image_4', $obj->pay_image_4), '附加截图4')?>
			<?=edit_form_uploader('pay_image_5',set_uploader('pay_image_5', $obj->pay_image_5), '附加截图5')?>
			<?=edit_form_textarea('remark', set_value('remark', $obj->remark), '备注信息','width:100%')?>
			<div style="display:none;">
			<?=edit_form_input('operator_id',set_value('operator_id',$obj->operator_id?$obj->operator_id:$currentAdminId),'接单者id')?>
			</div>
		</div>
		<div style="clear:both;"></div>
		<div class="modal-footer">
			<button type="button" data-dismiss="modal" class="btn default">关闭</button>
			<button type="submit" class="btn btn-primary"><?=$action=='add'?'添加':'修改'?></button>
		</div>

	</div>
<?=form_close()?>
<script type="text/javascript">

function resetFeesAndTotal (no_fees_total_money){
	$('#pay_total').val(no_fees_total_money);
	$('#fees').val('');
}

$(document).ready(function(){
	$("#order_time").ECalendar({
		 type:"date",   //模式，time: 带时间选择; date: 不带时间选择;
		 stamp : false,   //是否转成时间戳，默认true;
		 offset:[0,2],   //弹框手动偏移量;
		 format:"yyyy/mm/dd",   //时间格式 默认 yyyy-mm-dd hh:ii;
		 skin:5,   //皮肤颜色，默认随机，可选值：0-8,或者直接标注颜色值;
		 step:10,   //选择时间分钟的精确度;
		 callback:function(v,e){} //回调函数
	});
	$("#pay_time").ECalendar({
		 type:"date",   //模式，time: 带时间选择; date: 不带时间选择;
		 stamp : false,   //是否转成时间戳，默认true;
		 offset:[0,2],   //弹框手动偏移量;
		 format:"yyyy/mm/dd",   //时间格式 默认 yyyy-mm-dd hh:ii;
		 skin:2,   //皮肤颜色，默认随机，可选值：0-8,或者直接标注颜色值;
		 step:10,   //选择时间分钟的精确度;
		 callback:function(v,e){} //回调函数
	});


	//处理手续费
	(function(){
		var product_amount = $('#product_amount');
		var yunfei = $('#yunfei');
		var pay_total = $('#pay_total');
		var coin_type = $('#coin_type');
		var pay_account = $('#pay_account');
		var commission = $('#commission');
		var fees = $('#fees');
		var intror_coin_type = $('#intror_coin_type');
		var intror_pay_account = $('#intror_pay_account');
		var intror_commission = $('#intror_commission');
		var intror_fees = $('#intror_fees');
		var culculate = $('#culculate');

		var culculateFees = function(money_num,coin_type){
			if(!(money_num>0)){
				return 0.00;
			}
			var retFees;
			switch(coin_type){
			case 1:		//美元/加元
				retFees = parseFloat(((parseFloat(money_num)+0.4)/0.948)-parseFloat(money_num)).toFixed(2);
				break;
			case 2:		//欧元
				retFees = parseFloat(((parseFloat(money_num)+0.35)/0.948)-parseFloat(money_num)).toFixed(2);
				break;
			case 3:		//人民币
				retFees = 0.00;
				break;
			case 4:		//英镑
				retFees = parseFloat(((parseFloat(money_num)+0.2)/0.948)-parseFloat(money_num)).toFixed(2);
				break;
			case 5:		//日元
				retFees = parseFloat(((parseFloat(money_num)+40)/0.948)-parseFloat(money_num)).toFixed(2);
				break;
			}
			return retFees;
		};

		

		$(culculate).click(function(){
			var product_amount_val = $(product_amount).val();
			var yunfei_val = $(yunfei).val()?$(yunfei).val():0.00;
			var coin_type_val = $(coin_type).val();
			var pay_account_val = $(pay_account).val();
			var commission_val = $(commission).val()?$(commission).val():0.00;
			var intror_coin_type_val = $(intror_coin_type).val();
			var intror_pay_account_val = $(intror_pay_account).val();
			var intror_commission_val = $(intror_commission).val()?$(intror_commission).val():0.00;
			
			if(!product_amount_val){
				alert('商品金额不能为空!');
				$(product_amount).focus();
				return false;
			}

			if(pay_account_val && intror_pay_account_val){			//设置了客户收款账号，设置为中介收款账号
				//中介的手续费为中介要求的中介费算的。
				var intror_commission_floatVal = parseFloat(intror_commission_val).toFixed(2);
				var intror_coin_type_intVal = parseInt(intror_coin_type_val);
				var intror_fees_floatVal = culculateFees(intror_commission_floatVal,intror_coin_type_intVal);
				$(intror_fees).val(intror_fees_floatVal);	//设置中介手续费
				//客户的手续费为：商品价格+运费+客户要求的佣金 按公式算出来
				var customer_benjin = (parseFloat(product_amount_val)+parseFloat(yunfei_val)+parseFloat(commission_val)).toFixed(2);
				var fees_floatVal = culculateFees(customer_benjin,parseInt(coin_type_val));
				$(fees).val(fees_floatVal);

				var pay_total_floatVal = (parseFloat(customer_benjin)+parseFloat(fees_floatVal)+parseFloat(intror_commission_floatVal)+parseFloat(intror_fees_floatVal)).toFixed(2);
				$(pay_total).val(pay_total_floatVal);
				$('#summry').html('商品价格 '+parseFloat(product_amount_val).toFixed(2)+
						' + 运费 '+parseFloat(yunfei_val).toFixed(2)+
						' + 客户佣金 '+parseFloat(commission_val).toFixed(2)+
						' = '+parseFloat(customer_benjin).toFixed(2)+
						' , 手续费= '+parseFloat(fees_floatVal).toFixed(2)+
						' , 包含手续费共需支付给客户= '+(parseFloat(customer_benjin)+parseFloat(fees_floatVal)).toFixed(2)+
						'<br/>中介费= '+parseFloat(intror_commission_floatVal).toFixed(2)+
						' , 中介手续费= '+parseFloat(intror_fees_floatVal).toFixed(2)+
						' , 包含手续费共需支付给中介= '+(parseFloat(intror_commission_floatVal)+parseFloat(intror_fees_floatVal)).toFixed(2)+
						'<br/>包含客户手续费总共支付 '+parseFloat(pay_total_floatVal).toFixed(2)+
						' , 不含客户手续费总共支付   <a onclick="resetFeesAndTotal('+(parseFloat(customer_benjin)+parseFloat(intror_commission_floatVal)+parseFloat(intror_fees_floatVal)).toFixed(2)+')">' +(parseFloat(customer_benjin)+parseFloat(intror_commission_floatVal)+parseFloat(intror_fees_floatVal)).toFixed(2)+'</a>');
				
			}else if(pay_account_val && !intror_pay_account_val){	//设置了客户收款 账号，未设置中介收款 账号
				//客户的手续费为：商品价格+运费+客户要求的佣金 按公式算出来
				var customer_benjin = (parseFloat(product_amount_val)+parseFloat(yunfei_val)+parseFloat(commission_val)).toFixed(2);
				var fees_floatVal = culculateFees(customer_benjin,parseInt(coin_type_val));
				$(fees).val(fees_floatVal);
				//中介为空
				$(intror_commission).val('');
				$(intror_fees).val('');
				//总支付
				var pay_total_floatVal = (parseFloat(customer_benjin)+parseFloat(fees_floatVal)).toFixed(2);
				$(pay_total).val(pay_total_floatVal);
				$('#summry').html('商品价格 '+parseFloat(product_amount_val).toFixed(2)+
						' + 运费 '+parseFloat(yunfei_val).toFixed(2)+
						' + 客户佣金 '+parseFloat(commission_val).toFixed(2)+
						' = '+parseFloat(customer_benjin).toFixed(2)+
						' , 手续费= '+parseFloat(fees_floatVal).toFixed(2)+
						' , 包含手续费共需支付给客户= '+(parseFloat(customer_benjin)+parseFloat(fees_floatVal)).toFixed(2)+
						'<br/>包含手续费总共支付 '+parseFloat(pay_total_floatVal).toFixed(2)+
						' , 不包含手续费总共支付  <a onclick="resetFeesAndTotal('+parseFloat(customer_benjin).toFixed(2)+')">'+parseFloat(customer_benjin).toFixed(2)+'</a>');

			}else if(!pay_account_val && intror_pay_account_val){	//未设置客户收款 账号，设置了中介收款 账号
				//客户为空
				$(commission).val('');
				$(fees).val('');
				//中介
				var intror_benjin = (parseFloat(product_amount_val)+parseFloat(yunfei_val)+parseFloat(intror_commission_val)).toFixed(2);
				var intror_fees_floatVal = culculateFees(intror_benjin,parseInt(intror_coin_type_val));
				$(intror_fees).val(intror_fees_floatVal);	//设置中介手续费
				//总支付
				var pay_total_floatVal = (parseFloat(intror_benjin)+parseFloat(intror_fees_floatVal)).toFixed(2);
				$(pay_total).val(pay_total_floatVal);
				$('#summry').html('商品价格 '+parseFloat(product_amount_val).toFixed(2)+
						' + 运费 '+parseFloat(yunfei_val).toFixed(2)+
						' + 中介费 '+parseFloat(intror_commission_val).toFixed(2)+
						' = '+parseFloat(intror_benjin).toFixed(2)+
						' , 中介手续费= '+parseFloat(intror_fees_floatVal).toFixed(2)+
						' , 包含手续费共需支付给中介= '+(parseFloat(intror_benjin)+parseFloat(intror_fees_floatVal)).toFixed(2)+
						'<br/>总共支付 '+parseFloat(pay_total_floatVal).toFixed(2));
				

			}else if(!pay_account_val && !intror_pay_account_val){	//未设置客户收款 账号，未设置中介收款 账号
				alert('客户收款账号、中介收款 账号至少设置一个！');
			}
		});
		
	})();
	
});
function submitForm() {
	/*
	if(confirm("确定要删除吗？")){
	 	return true;
	}else{
		return false;
	}*/
	return true;
}
</script>

<script type="text/javascript">
$(document).ready(function(){
	AjaxUploader.uploadTempUrl = "<?=site_url('/common/AjaxUpload/upload') . '/'  ?>";
	AjaxUploader.init();
});
</script>